import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_module2/home/_interface/BottomNavigationClick.dart';

// BottomNavigationBar 默认的实例
class HomeBottomNavigationBar extends StatefulWidget {
  BottomNavigationClick bottomNavigationClick ;
  HomeBottomNavigationBar(this.bottomNavigationClick) : super();

  @override
  State<StatefulWidget> createState() => _HomeBottomNavigationBar(bottomNavigationClick);
}

// BottomNavigationBar 默认的实例,有状态
class _HomeBottomNavigationBar extends State {
  BottomNavigationClick bottomNavigationClick ;
  _HomeBottomNavigationBar(this.bottomNavigationClick);

  int _currentIndex = 1;

  void _onItemTapped(int index) {

    if (mounted) {
      setState(() {
        bottomNavigationClick.click(index);
        _currentIndex = index;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return BottomNavigationBar(
      type: BottomNavigationBarType.fixed,
      // BottomNavigationBarType 中定义的类型，有 fixed 和 shifting 两种类型
      iconSize: 20.0,
      // BottomNavigationBarItem 中 icon 的大小
      currentIndex: _currentIndex,
      // 当前所高亮的按钮index
      onTap: _onItemTapped,
      // 点击里面的按钮的回调函数，参数为当前点击的按钮 index
      fixedColor: Colors.blue,
      // 如果 type 类型为 fixed，则通过 fixedColor 设置选中 item 的颜色
      items: <BottomNavigationBarItem>[
        BottomNavigationBarItem(
            title: Text("钱包"),
            icon: Image.asset("assets/images/icon_asset_selected_false.webp",width: 20, height: 20,),
            activeIcon: Image.asset("assets/images/icon_asset_selected_true.webp",width: 20, height: 20,)),
        BottomNavigationBarItem(
            title: Text("交易"),
            icon: Image.asset("assets/images/icon_ex_change_normal.webp",width: 20, height: 20,),
            activeIcon: Image.asset("assets/images/icon_ex_change_press.webp",width: 20, height: 20,)),
        BottomNavigationBarItem(
            title: Text("Dapp"),
            icon: Image.asset("assets/images/icon_action_selected_false.webp",width: 20, height: 20,),
            activeIcon: Image.asset("assets/images/icon_action_selected_true.webp",width: 20, height: 20,)),
        BottomNavigationBarItem(
            title: Text("个人"),
            icon: Image.asset("assets/images/icon_personal_selected_false.webp",width: 20, height: 20,),
            activeIcon: Image.asset("assets/images/icon_personal_selected_true.webp",width: 20, height: 20,))
      ],
    );
  }
}
